package com.zx.oa.controller;

import com.alibaba.fastjson.JSON;
import com.zx.oa.entity.ClassInfo;
import com.zx.oa.service.census.CensusService;
import com.zx.oa.service.census.CensusServicelpml;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/getClassName.do")
public class MoringCascadeServelt extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String param = req.getParameter("majorName");
        CensusService censusService=new CensusServicelpml();
        List<ClassInfo> classInfoList=censusService.getClassAll(param);
        String jsonclass = JSON.toJSONString(classInfoList);
        resp.setContentType("text/html;charset=utf-8");
        resp.setCharacterEncoding("UTF-8");
        PrintWriter out=resp.getWriter();
        out.print(jsonclass);
        out.flush();
        out.close();

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
